<?php

class Register extends TPage
{
	public function onLoad($param)
	{
		parent::onLoad($param);
	}
	
	public function validateLogin($sender,$param)
	{
		$user_manager = $this->Application->Modules['users'];
		$unactivated_user_manager = $this->Application->Modules['unactivated_users'];
		if(	$user_manager->isLoginReserved($this->login->Text) ||
			$unactivated_user_manager->isLoginReserved($this->login->Text))
			$param->IsValid = false;
		else
			$param->IsValid = true;
	}
	
	public function saveButtonClicked($sender, $params)
	{
		if($this->IsValid == false)
			return;
			
		$unactivated_user_manager = $this->Application->Modules['unactivated_users'];
		$result = $unactivated_user_manager->addUnactivatedUser(
										String::format($this->login->Text),
										String::format($this->password->Text),
										String::format($this->first_name->Text),
										String::format($this->last_name->Text),
										$this->email->Text,
										DateTimeParser::getCurrentDateTime()
		);
		if($result instanceof UnactivatedUserRecord)
			$this->Response->redirect($this->Service->constructUrl('user.RegisterComplete'));
	}
}

?>